package com.neusoft.utils.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;


public class DateUtil extends org.apache.commons.lang3.time.DateUtils {
	public static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss";
	public static final String SHORT_PATTERN = "yyyy-MM-dd";
	private static final TimeZone GMT = TimeZone.getTimeZone("GMT");

	private DateUtil() {
	}

	public static TimeZone getGMTTimeZone() {
		return GMT;
	}

	public static String dateString(Date date) {
		return format("yyyyMMdd", date);
	}

	public static String dateString() {
		return dateString(new Date());
	}

	private static TimeZone getDefaultTimeZone() {
		return null;
	}


	public static Date parseE(String dateText) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat();
		TimeZone timeZone = getDefaultTimeZone();
		if (timeZone != null) {
			sdf.setTimeZone(timeZone);
		}
		return sdf.parse(dateText);
	}

	public static Date parse(String format, String dateText) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		TimeZone timeZone = getDefaultTimeZone();
		if (timeZone != null) {
			sdf.setTimeZone(timeZone);
		}
		return sdf.parse(dateText);
	}

	public static String format(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat();
		TimeZone timeZone = getDefaultTimeZone();
		if (timeZone != null) {
			sdf.setTimeZone(timeZone);
		}
		return sdf.format(date);
	}

	public static String format(String format, Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		TimeZone timeZone = getDefaultTimeZone();
		if (timeZone != null) {
			sdf.setTimeZone(timeZone);
		}
		return sdf.format(date);
	}

}
